package com.fatdetection.demo.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Component
public class UploadUtils {
    @Value("${userFileSavedPath}")
    private String fileSavedPath;

    public Boolean uploadFile(MultipartFile[] files){
        if(files == null || files.length == 0){
            return false;
        }else{
            for (MultipartFile file : files) {
                String filename = file.getOriginalFilename();
                try {
                    file.transferTo(new File(fileSavedPath + filename));
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
        }
        return true;
    }

}
